const obj = {
    name: "Hydra",
    age: 35,
    friend: {
        name: "nzx",
        age: 20,
        friend: {
            name: "csy",
            age: 19,
        }
    }
}

function deepCopy(obj) {
    const newObj = {};
    for (const k in obj) {
        const value = obj[k];
        if (typeof value == 'object') {
            newObj[k] = deepCopy(value);
        } else {
            newObj[k] = value
        }
    }
    return newObj;
}

console.log(deepCopy(obj));